# -*- coding: utf-8 -*-

import cv2 as cv
import os
import matplotlib.pyplot as plt

IMG_INPUT_FILE = "../../../data/imgs/pc_cocal.jpg"
IMG_OUTPUT_DIR = "../../../data/imgs/output"

IMG = cv.imread('../../../data/imgs/pc_cocal.jpg')

res_1 = cv.resize(IMG, None, fx=2, fy=2, interpolation=cv.INTER_CUBIC)
# or
height, width = IMG.shape[:2]
res_2 = cv.resize(IMG, (width//4, height//4), interpolation=cv.INTER_CUBIC)

if __name__ == "__main__":

    if not os.path.exists(IMG_OUTPUT_DIR):
        os.mkdir(IMG_OUTPUT_DIR)
    cv.imwrite(IMG_OUTPUT_DIR + "/" + "pa_cocal_xh.jpg", res_1)
    cv.imwrite(IMG_OUTPUT_DIR + "/" + "pa_cocal_s.jpg", res_2)

    plt.subplot(121)
    plt.imshow(IMG)
    plt.subplot(122)
    # opencv 3通道图像BGR, matplotlib则为rgb, 使用plt.show()之前需要转换
    B, G, R = cv.split(IMG)
    IMG_RGB = cv.merge([R, G, B])
    plt.imshow(IMG_RGB)

    plt.show()
